package com.gc.controller;

import com.gc.common.constants.SysConstants;
import com.gc.common.resp.ApiResult;
import com.gc.dto.ClientDTO;
import com.gc.pojo.SysClient;
import com.gc.pojo.SysTemplate;
import com.gc.services.ClientService;
import com.gc.services.TemplateService;
import com.gc.services.VorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("client")
public class ClientController {
    @Autowired
    private ClientService clientService;
    @Autowired
    private TemplateService templateService;
    @Autowired
    private VorService vorService;

    @GetMapping("all")
    @ResponseBody
    public List<ClientDTO> getAllClient(){
        return clientService.getAllClientDTO();
    }

    @GetMapping("add-view")
    public ModelAndView addView(){
        ModelAndView mav = new ModelAndView("client/add");
        List<SysTemplate> all = templateService.getAll();
        mav.addObject("templates",all);
        return mav;
    }

    @PostMapping("add")
    @ResponseBody
    public ApiResult add(@RequestBody SysClient client){
        client.setCreateTime(new Date());
        int count1 =  clientService.addClient(client);
        return new ApiResult();
    }


    @PostMapping("remove")
    @ResponseBody
    public ApiResult add(@RequestParam Integer clientId){
        int count1 =  clientService.remove(clientId);
        return new ApiResult();
    }
    @PostMapping("modify")
    @ResponseBody
    public ApiResult modify(@RequestBody SysClient client){
        int count1 =  clientService.modify(client);
        //todo 修改 当前客户下的所有报告模板
        return new ApiResult();
    }


    @GetMapping("get")
    @ResponseBody
    public SysClient get(@RequestParam Integer clientId){
        SysClient client =  clientService.getClientById(clientId);
        return client;
    }
}
